<?php 
class Mmusic extends CI_Model {
	public  function __construct() {
		parent::__construct();
	    $this->load->database();
	}
	public function getTopSong($limit) {
		$result=$this->db->query("SELECT song.idSong,song.idAlbum,song.idArtist,album.strNameAlbum,album.strReview,song.strPath,artist.strArtist,song.strExtraArtist,song.strFileName,song.rating 
			FROM song 
			LEFT JOIN album ON CONVERT(song.idAlbum USING utf8) =CONVERT(album.idAlbum USING utf8)
			LEFT JOIN artist ON CONVERT(song.idArtist USING utf8)=CONVERT(artist.idArtist USING utf8) ORDER BY rating DESC limit 0,$limit");
		return $result->result_array();
	}

	public function getMusic($id) {
		$result=$this->db->query("SELECT song.idSong,song.idAlbum,song.idArtist,album.strNameAlbum,song.strPath,artist.strArtist,song.strExtraArtist,song.strFileName,song.rating
			FROM song 
			LEFT JOIN album ON CONVERT(song.idAlbum USING utf8) =CONVERT(album.idAlbum USING utf8)
			LEFT JOIN artist ON CONVERT(song.idArtist USING utf8)=CONVERT(artist.idArtist USING utf8)
            WHERE idSong LIKE'".$id."'");
		return $result->result_array();

	}

	public function getSongInfo($id) {
		$result=$this->db->query("SELECT song.idSong,song.idAlbum,song.idArtist,song.idGenre,song.idTheme,song.strExtraArtist,song.strFileName,song.rating,song.comment,album.strNameAlbum,artist.strArtist,genre.strGenre,theme.strTheme
			FROM song 
			LEFT JOIN album ON CONVERT(song.idAlbum USING utf8) =CONVERT(album.idAlbum USING utf8)
			LEFT JOIN artist ON CONVERT(song.idArtist USING utf8)=CONVERT(artist.idArtist USING utf8)
			LEFT JOIN theme ON CONVERT(song.idTheme USING utf8)=CONVERT(theme.idTheme USING utf8)
			LEFT JOIN genre ON CONVERT(song.idGenre USING utf8)=CONVERT(genre.idGenre USING utf8)
            WHERE idSong LIKE'".$id."'");
		return $result->result_array();
	}

	public function getAllSong() {
		$result=$this->db->query("SELECT song.idSong,song.idAlbum,song.idArtist,album.strNameAlbum,album.strReview,song.strPath,artist.strArtist,song.strExtraArtist,song.strFileName,song.rating 
			FROM song 
			LEFT JOIN album ON CONVERT(song.idAlbum USING utf8) =CONVERT(album.idAlbum USING utf8)
			LEFT JOIN artist ON CONVERT(song.idArtist USING utf8)=CONVERT(artist.idArtist USING utf8)");
		return $result->result_array();
	}
	public function updateRating($id,$value) {
		$this->db->query("UPDATE song 
								 SET rating=$value
								 WHERE idSong='$id'");
	}


	
} 
 ?>